package xw.qxypt.modules.baseinfo.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import xw.qxypt.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import xw.qxypt.modules.baseinfo.entity.LhpUserWaysectroleRelationEntity;
import xw.qxypt.modules.baseinfo.service.LhpUserWaysectroleRelationService;
import xw.qxypt.common.utils.PageUtils;
import xw.qxypt.common.utils.R;



/**
 * 用户-路段角色 关系表
 *
 * @author xw
 * @email 
 * @date 2019-12-19 15:24:39
 */
@RestController
@RequestMapping("baseinfo/lhpuserwaysectrolerelation")
public class LhpUserWaysectroleRelationController {
    @Autowired
    private LhpUserWaysectroleRelationService lhpUserWaysectroleRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("baseinfo:lhpuserwaysectrolerelation:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = lhpUserWaysectroleRelationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("baseinfo:lhpuserwaysectrolerelation:info")
    public R info(@PathVariable("id") String id){
        LhpUserWaysectroleRelationEntity lhpUserWaysectroleRelation = lhpUserWaysectroleRelationService.getById(id);

        return R.ok().put("lhpUserWaysectroleRelation", lhpUserWaysectroleRelation);
    }


    /**
     * 信息
     */
    @RequestMapping("/getByRoleId/{roleId}")
    public R getByRoleId(@PathVariable("roleId") String roleId){
        List<LhpUserWaysectroleRelationEntity> list=lhpUserWaysectroleRelationService.getByRoleId(roleId);
        return R.ok().put("list", list);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("baseinfo:lhpuserwaysectrolerelation:save")
    public R save(@RequestBody LhpUserWaysectroleRelationEntity lhpUserWaysectroleRelation){
        lhpUserWaysectroleRelationService.save(lhpUserWaysectroleRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("baseinfo:lhpuserwaysectrolerelation:update")
    public R update(@RequestBody LhpUserWaysectroleRelationEntity lhpUserWaysectroleRelation){
        ValidatorUtils.validateEntity(lhpUserWaysectroleRelation);
        lhpUserWaysectroleRelationService.updateById(lhpUserWaysectroleRelation);
        
        return R.ok();
    }

    /**
     * 批量修改关联关系
     */
    @RequestMapping("/updateRelation")
    public R updateRelation(@RequestParam Map<String, Object> params){
        lhpUserWaysectroleRelationService.updateRelation(params);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("baseinfo:lhpuserwaysectrolerelation:delete")
    public R delete(@RequestBody String[] ids){
        lhpUserWaysectroleRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
